#include "consensus.h"
#include "../lfqueue/iqueue.h"

template <class T>
class QueueConsensus : public Consensus<T> {
	public :

	QueueConsensus(IQueue<bool> *pqueue, int N):
		Consensus<T>(N) {
		pqueue_ = pqueue;
		pqueue_->Enqueue(true);
		pqueue_->Enqueue(false);
	}
	
	virtual T Decide() {
		size_t i = omp_get_thread_num();
		assert(i < this->N_);
		bool status = false;
		assert(pqueue_->Dequeue(&status));
		if (status)
			return this->proposed_[i];
		return this->proposed_[1 - i];
	}
	
	private :
	
	IQueue<bool> *pqueue_;
	
};
